package com.simulation.web.controller.tech;

import cn.hutool.core.bean.BeanUtil;
import com.simulation.common.core.domain.AjaxResult;
import com.simulation.web.dto.TechReplyDTO;
import com.simulation.web.domain.TechReply;
import com.simulation.web.service.impl.ReplyServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("项目-回复")
@RestController
@RequestMapping("techReply")
@AllArgsConstructor
public class TechReplyController {

    private final ReplyServiceImpl replyService;

    @GetMapping("getPage")
    @ApiOperation("分页查询回复")
    public AjaxResult getPage(TechReplyDTO techReplyDTO) {
        return AjaxResult.success(replyService.getPage(techReplyDTO));
    }

    /**
     * 查询所有记录
     *
     * @return 返回集合，没有返回空List
     */
    @RequestMapping("list")
    public List<TechReply> listAll() {
        return replyService.listAll();
    }


    /**
     * 根据主键查询
     *
     * @param id 主键
     * @return 返回记录，没有返回null
     */
    @GetMapping("getById")
    public TechReply getById(Long id) {
        return replyService.getById(id);
    }    
     
    /**
     * 新增，忽略null字段
     *
     * @param techReplyDTO 新增的记录
     * @return 返回影响行数
     */
    @PostMapping("insert")
    @ApiOperation("新增回复")
    public AjaxResult insert(@RequestBody TechReplyDTO techReplyDTO) {
        TechReply techReply = new TechReply();
        BeanUtil.copyProperties(techReplyDTO, techReply);
        replyService.insertIgnoreNull(techReply);
        return AjaxResult.success();
    }    
      
    /**
     * 修改，忽略null字段
     *
     * @param techReply 修改的记录
     * @return 返回影响行数
     */
    @PostMapping("update")
    public int update(@RequestBody TechReply techReply) {
        return replyService.updateIgnoreNull(techReply);
    }
    
    /**
     * 删除记录
     *
     * @param techReplyDTO 待删除的记录
     * @return 返回影响行数
     */
    @PostMapping("delete")
    @ApiOperation("删除回复")
    public AjaxResult delete(@RequestBody TechReplyDTO techReplyDTO) {
        replyService.delete(techReplyDTO.getId());
        return AjaxResult.success();
    }
    
}